/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class ctrl_ShareholderAmendment_Test {

    static testMethod void myUnitTest() 
    {
        // TO DO: implement unit test
        
        //Account Object Record...
        Account accountObject = new Account();
        accountObject.Name = 'Test Account';
        //accountObject.LicenseNumber__c = serialObject.id;
        accountObject.License_Application_Step__c = 'Record Created';
        accountObject.License_Application_Type__c = 'New License';
        accountObject.Activity__c = 'Trading - Three Activity';
        accountObject.License_Issue_Date__c = system.today();
        accountObject.License_Expiry_Date__c = System.Today().addYears(1);
        accountObject.Master_Account_Flag__c = true;
        insert accountObject;
        
        Contact contactObject1 = new Contact();
        contactObject1.LastName = 'Test 2 Shareholder';
        contactObject1.AccountId = accountObject.id;
        contactObject1.Contact_Type__c = 'Shareholder';
        insert contactObject1;
                      
        Contact contactObject2 = new Contact();
        contactObject2.LastName = 'Test 2 Shareholder';
        contactObject2.AccountId = accountObject.id;
        contactObject2.Contact_Type__c = 'Shareholder';
        insert contactObject2;
        
        Share_Ownership__c shareOwnerObject1 = new Share_Ownership__c();
        shareOwnerObject1.Company__c = accountObject.Id;
        shareOwnerObject1.Ownership__c = 50;
        shareOwnerObject1.Share_Profit__c = 50;
        shareOwnerObject1.Shareholder__c = contactObject2.id;
        insert shareOwnerObject1;
        
        Share_Ownership__c shareOwnerObject2 = new Share_Ownership__c();
        shareOwnerObject2.Company__c = accountObject.Id;
        shareOwnerObject2.Ownership__c = 50;
        shareOwnerObject2.Share_Profit__c = 50;
        shareOwnerObject2.Shareholder__c = contactObject2.id;
        insert shareOwnerObject2;
        
        
        
        Map<string,RecordType> amendmentRecordTypeMap = new Map<string,RecordType>();
        Map<String,Amendment__c> amendmentObjectMap = new Map<string,Amendment__c>();
        
        for(RecordType tempObject : [SELECT Id,SObjectType,DeveloperName,IsActive FROM RecordType where SObjectType =: 'Amendment__c' And DeveloperName IN('Shareholder_Amendment_Add_Partner','Shareholder_Amendment_Change_Share_Percentage','Shareholder_Amendment_Remove_Partner','Shareholder_Amendment_Replace_Partner')])
        {
            amendmentRecordTypeMap.put(tempObject.DeveloperName, tempObject);
            
            Amendment__c amendmentObject1 = new Amendment__c();
            amendmentObject1.RecordTypeId = tempObject.Id;
            amendmentObject1.Account__c = accountObject.Id;
            amendmentObject1.New_Company_Name__c = 'Test New Name';
            amendmentObject1.New_Company_Name_Arabic__c = 'test New Name Arabic';
            
            //Adding in the Amendment Map...
            amendmentObjectMap.put(tempObject.DeveloperName,amendmentObject1);
            
        }
        
        //For Amendment Insertion...
        if(amendmentObjectMap.size() > 0)
            insert amendmentObjectMap.values();
            
        //For Amendment Object For Company License Type...
        /*Amendment__c amendmentObject1 = new Amendment__c();
        amendmentObject1.RecordTypeId = amendmentRecordTypeMap.get('Shareholder_Amendment_Add_Partner').Id;
        amendmentObject1.Account__c = accountObject.Id;
        amendmentObject1.New_Company_Name__c = 'Test New Name';
        amendmentObject1.New_Company_Name_Arabic__c = 'test New Name Arabic';
        insert amendmentObject1;*/
        
        //For ShareHolder Amendment Object Add Flag...
        Shareholder_Amendment__c shareAmendmentObject = new Shareholder_Amendment__c();
        shareAmendmentObject.Account__c = accountObject.id;
        //shareAmendmentObject.Amendment__c = amendmentObject1.Id;
        shareAmendmentObject.Amendment__c = amendmentObjectMap.get('Shareholder_Amendment_Add_Partner').Id;
        shareAmendmentObject.Add_Flag__c = true; 
        shareAmendmentObject.Ownership__c = 10;
        shareAmendmentObject.Share_Profit__c = 10;
        insert shareAmendmentObject;
        
        //For ShareHolder Amendment Object Edit Flag...
        Shareholder_Amendment__c shareAmendmentObject1 = new Shareholder_Amendment__c();
        shareAmendmentObject1.Account__c = accountObject.id;
        shareAmendmentObject1.Contact__c = contactObject1.id;
        shareAmendmentObject1.Share_Ownership__c = shareOwnerObject1.id;
        //shareAmendmentObject1.Amendment__c = amendmentObject1.Id;
        shareAmendmentObject1.Amendment__c = amendmentObjectMap.get('Shareholder_Amendment_Add_Partner').Id;
        shareAmendmentObject1.Edit_Flag__c = true; 
        shareAmendmentObject1.Ownership__c = 40;
        shareAmendmentObject1.Share_Profit__c = 40;
        insert shareAmendmentObject1;
        
        
        //For ShareHolder Amendment Object Delete Flag...
        Shareholder_Amendment__c shareAmendmentObject2 = new Shareholder_Amendment__c();
        shareAmendmentObject2.Account__c = accountObject.id;
        shareAmendmentObject2.Contact__c = contactObject2.id;
        shareAmendmentObject2.Share_Ownership__c = shareOwnerObject2.id;
        //shareAmendmentObject2.Amendment__c = amendmentObject1.Id;
        shareAmendmentObject2.Amendment__c = amendmentObjectMap.get('Shareholder_Amendment_Add_Partner').Id;
        shareAmendmentObject2.Delete_Flag__c = true; 
        shareAmendmentObject2.Ownership__c = 50;
        shareAmendmentObject2.Share_Profit__c = 50;
        insert shareAmendmentObject2;
        
        //Amendment Id Standard Controller...
        //ApexPages.StandardController amendmentExtendedObject = new ApexPages.StandardController(amendmentObject1);
        ApexPages.StandardController amendmentExtendedObject = new ApexPages.StandardController(amendmentObjectMap.get('Shareholder_Amendment_Add_Partner'));
        //ApexPages.CurrentPage().getParameters().put('id',amendmentObject1.id);
        ApexPages.CurrentPage().getParameters().put('id',amendmentObjectMap.get('Shareholder_Amendment_Add_Partner').Id);
        
        ctrl_ShareholderAmendment amendmentShareholderClass = new ctrl_ShareholderAmendment(amendmentExtendedObject);
        
        amendmentShareholderClass.generatePaymentModule();
        amendmentShareholderClass.additems();
        amendmentShareholderClass.RowIndex = 'j_id0:MainForm:j_id50:0:j_id52:0:EDITID';
        
        amendmentShareholderClass.EditAllow();
        amendmentShareholderClass.updateitemlist();
        amendmentShareholderClass.cancelEdit();
        amendmentShareholderClass.RowIndex = 'j_id0:MainForm:j_id50:0:j_id52:0:EDITID';
        amendmentShareholderClass.DelAllow();
        
        ApexPages.StandardController amendmentExtendedObject1 = new ApexPages.StandardController(amendmentObjectMap.get('Shareholder_Amendment_Remove_Partner'));
        //ApexPages.CurrentPage().getParameters().put('id',amendmentObject1.id);
        ApexPages.CurrentPage().getParameters().put('id',amendmentObjectMap.get('Shareholder_Amendment_Remove_Partner').Id);
        
        
        ctrl_ShareholderAmendment amendmentShareholderClass1 = new ctrl_ShareholderAmendment(amendmentExtendedObject1);
        amendmentShareholderClass1.generatePaymentModule();    
        
        ApexPages.StandardController amendmentExtendedObject2 = new ApexPages.StandardController(amendmentObjectMap.get('Shareholder_Amendment_Change_Share_Percentage'));
        //ApexPages.CurrentPage().getParameters().put('id',amendmentObject1.id);
        ApexPages.CurrentPage().getParameters().put('id',amendmentObjectMap.get('Shareholder_Amendment_Change_Share_Percentage').Id);
        
        ctrl_ShareholderAmendment amendmentShareholderClass2 = new ctrl_ShareholderAmendment(amendmentExtendedObject2);
        amendmentShareholderClass2.generatePaymentModule();
        
        
        ApexPages.StandardController amendmentExtendedObject3 = new ApexPages.StandardController(amendmentObjectMap.get('Shareholder_Amendment_Replace_Partner'));
        //ApexPages.CurrentPage().getParameters().put('id',amendmentObject1.id);
        ApexPages.CurrentPage().getParameters().put('id',amendmentObjectMap.get('Shareholder_Amendment_Replace_Partner').Id);
        
        ctrl_ShareholderAmendment amendmentShareholderClass3 = new ctrl_ShareholderAmendment(amendmentExtendedObject3);
        amendmentShareholderClass3.generatePaymentModule();
    
    
    
    }
}